﻿function Main_Index() {

	// 表单
	var form = new Ext.FormPanel({
		height: 305,
		border: true,
		labelWidth: 90, // 注意 使用时 如果有表单内组件有特殊标签名称长度很大 替换合适的标签长度
		labelAlign: 'right',
		//frame: true,
		layout: 'form',
		bodyStyle: 'padding:5px 5px 0',
		// 注意 这是传入方法的 Ext.data.DataReader 类型
		//reader : formReader,
		items: [{
			layout: 'column', // 注意 现在使用的是两列 要是三列或更多
			// 请改变下面的items
			// 并在上面定义每个列的组件集合
			items: [{
				columnWidth: .5,
				bodyStyle: 'padding:1px',
				layout: 'form',
				defaultType: 'textfield',
				items: firstColumn
			}, {
				columnWidth: .5,
				bodyStyle: 'padding:1px',
				layout: 'form',
				defaultType: 'textfield',
				//items: secondColumn
				items: firstColumn
			}],
			buttonAlign: 'center',
			buttons: [new Ext.ux.SubmitBtn({})]
		}],
		buttonAlign: 'center'
	});

	// 定义表单单独列的组件对象集合
	var singleColumn = [{
		xtype: 'textarea',
		fieldLabel: '描述',
		name: 'Description',
		height: 50,
		width: 430
	}];

	var firstColumn = [{
		fieldLabel: '登录名<span style="color: red;" >*</span>',
		width: 150,
		name: 'LoginName',
		disabled: true
	}, {
		fieldLabel: '代码<span style="color: red;" >*</span>',
		disabled: true,
		width: 150,
		name: 'Code'
	}];

	var secondColumn = [{
		xtype: 'sicombo',
		id: 'Infra_DictCategory_Combobox_1',
		store: p_DictCategoryStore,
		mode: 'remote',
		listWidth: 250,
		tpl: new Ext.XTemplate(
							'<div class="x-grid3"><div><table>',
							'<thead class="x-grid3-header"><tr class="x-grid3-hd-row">',
							'<td class="x-grid3-hd x-grid3-cell x-grid3-hd-inner" style="width: 50px;color: blue;">字典编码</td>',
							'<td class="x-grid3-hd x-grid3-cell" style="width: 200px;color: blue;">字典名称</td>',
							'</tr></thead><tbody>',
							'<tpl for=".">',
							'<tr class="x-combo-list-item">',
							'<td class="x-grid3-col x-grid3-cell"><div class="x-grid3-cell-inner"  style="font-size:12px;">{TreeCode}</div></td>',
							'<td class="x-grid3-col x-grid3-cell"><div class="x-grid3-cell-inner"  style="font-size:12px;">{Name}</div></td>',
							'</tr>', '</tpl>', '</tbody></table></div></div>')
	}];

	////////////////////////
	// 参数字典下拉测试
	////////////////////////
	//url: '/Index/GetDicCategoryQueryList',
	// DictCategory Store
	var p_DictCategoryStore = new Ext.data.JsonStore({
		url: '/InfraDicCategory/GetDicCategoryQueryList',
		root: 'data',
		totalProperty: 'total',
		id: 'Id',
		fields: [{
			name: 'Id',
			type: 'string'
		}, {
			name: 'Name',
			type: 'string'
		}, {
			name: 'TreeCode',
			type: 'string'
		}]
	});

	//DictCategory Combo
	var p_dictCategoryCombo = new Ext.form.ComboBox({
		id: 'Infra_DictCategory_Combobox',
		store: p_DictCategoryStore,
		mode: 'remote',
		listWidth: 250,
		tpl: new Ext.XTemplate(
							'<div class="x-grid3"><div><table>',
							'<thead class="x-grid3-header"><tr class="x-grid3-hd-row">',
							'<td class="x-grid3-hd x-grid3-cell x-grid3-hd-inner" style="width: 50px;color: blue;">字典编码</td>',
							'<td class="x-grid3-hd x-grid3-cell" style="width: 200px;color: blue;">字典名称</td>',
							'</tr></thead><tbody>',
							'<tpl for=".">',
							'<tr class="x-combo-list-item">',
							'<td class="x-grid3-col x-grid3-cell"><div class="x-grid3-cell-inner"  style="font-size:12px;">{Code}</div></td>',
							'<td class="x-grid3-col x-grid3-cell"><div class="x-grid3-cell-inner"  style="font-size:12px;">{Name}</div></td>',
							'</tr>', '</tpl>', '</tbody></table></div></div>')
	});

	/////////////////////

	var btn = new Ext.Button({
		text: '友情提示：菜单在左边',
		handler: function () {
			Ext.MessageBox.alert('提示框', '何大，谁与我争疯！');
			Infrastructure.Params.DictionaryStore.load();
		}
	});
	var btn2 = new Ext.Button({
		text: '因为项目中有个功能是用户可以设置默认打开页面的，所以菜单默认隐藏',
		handler: function () {
			Ext.MessageBox.alert('提示框', '何大，谁与我争疯！');
		}
	});
	var btn3 = new Ext.Button({
		text: '时间比较仓促，此Demo肯定存在一些小bug或漏洞<p>请多多支持.<p>---<b>何大</b>',
		height: 200,
		handler: function () {
			Ext.MessageBox.alert('提示框', '何大，谁与我争疯！');
		}
	});

	var combo1 = new Infrastructure.Params.InfraDictComboBox({
		store: Infrastructure.Params.DictionaryStore,
		filterValue: 'Color'
	});

	var combo2 = new Infrastructure.Params.InfraDictComboBox({
		store: Infrastructure.Params.DictionaryStore,
		filterValue: 'ApproveType'
	});

	var chooseCust = function () {
		var custGrid = new Infrastructure.CifCust.GridPanel({
			height: 500,
			selModel: new Ext.grid.CheckboxSelectionModel({
				header: '',
				singleSelect: true
			}),
			tbar: [{
				xtype: 'tbaraddbtn',
				text: '选择',
				handler: function (e) {
					custGrid.tbarSelect('选定记录返回吗?', 'afterSelect');
				}
			}],
			listeners: {
				'afterSelect': function (selRecord, rt) {
					if (rt) {
						tgField.setValue(selRecord.data.Id);
					}
				}
			}
		});
		var custGridWin = new Infrastructure.BaseWindow({
			title: '请选择客户',
			iconCls: 'car',
			width: 600,
			items: [custGrid]
		});
		custGridWin.show();
		custGrid.store.load();
	};

	// 选择返回
	var tgField = new Infrastructure.CifCust.CustSelectTrigger({
		width: 250,
		triggerClass: 'x-form-search-trigger', //按钮样式
		readOnly: false, //只读
		listeners: {
			'afterSelect': function (selRecord, rt) {
				if (rt) {
					alert('select return ');
					alert(selRecord);
				}
			}
		}
	});

	//获取流水号
	var tgField2 = new Ext.form.TriggerField({
		width: 250,
		onTriggerClick: function () {
			Ext.Ajax.request({
				url: '/Main/GetNewID',
				params: {
					'sqnocd': "CA"
				},
				success: function (response, opts) {
					var result = Ext.util.JSON.decode(response.responseText);
					if (result.success == false) {
						JsHelper.ShowError('操作失败:' + result.msg);
					} else {
						alert(result.id);
						tgField2.setValue(result.id);
					}
				},
				failure: function (form, action) {
					JsHelper.ShowActionError(action);
				}
			});
		}, //单击事件
		triggerClass: 'x-form-search-trigger', //按钮样式
		readOnly: false, //只读
		fieldLabel: 'label'
	});

	var panel_1 = new Ext.Panel({
		title: '一个panel',
		items: [btn2, btn, btn3, combo1, combo2, tgField, tgField2]
	});

	var pannel_form = new Ext.Panel({
		title: '一个panel',
		items: [form]
	});

	JsHelper.ExtTabDoLayout(panel_1); // 注意这里把panel组件加到当前的tabpanel里
	//JsHelper.ExtTabDoLayout(pannel_form); // 注意这里把panel组件加到当前的tabpanel里
}

///alert('6222266');
//alert(window.location.host);
Ext.onReady(function () {
	Main_Index(); // 执行方法
});